home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / site-packages / psyco / logger.py < prev    next >
Text File  |  2006-03-29  |  3KB  |  91 lines

  1. ###########################################################################
  2. #  Psyco logger.
  3. #   Copyright (C) 2001-2002  Armin Rigo et.al.
  4.  
  5. """Psyco logger.
  6.  
  7. See log() in core.py.
  8. """
  9. ###########################################################################
  10.  
  11.  
  12. import _psyco
  13. from time import time, localtime, strftime
  14.  
  15.  
  16. current = None
  17. print_charges = 10
  18. dump_delay = 0.2
  19. dump_last = 0.0
  20.  
  21. def write(s, level):
  22.     t = time()
  23.     f = t-int(t)
  24.     current.write("%s.%02d  %-*s%s\n" % (
  25.         strftime("%X", localtime(int(t))),
  26.         int(f*100.0), 63-level, s,
  27.         "%"*level))
  28.     current.flush()
  29.  
  30. def psycowrite(s):
  31.     t = time()
  32.     f = t-int(t)
  33.     current.write("%s.%02d  %-*s%s\n" % (
  34.         strftime("%X", localtime(int(t))),
  35.         int(f*100.0), 60, s.strip(),
  36.         "% %"))
  37.     current.flush()
  38.  
  39. ##def writelines(lines, level=0):
  40. ##    if lines:
  41. ##        t = time()
  42. ##        f = t-int(t)
  43. ##        timedesc = strftime("%x %X", localtime(int(t)))
  44. ##        print >> current, "%s.%03d  %-*s %s" % (
  45. ##            timedesc, int(f*1000),
  46. ##            50-level, lines[0],
  47. ##            "+"*level)
  48. ##        timedesc = " " * (len(timedesc)+5)
  49. ##        for line in lines[1:]:
  50. ##            print >> current, timedesc, line
  51.  
  52. def writememory():
  53.     write("memory usage: %d+ kb" % _psyco.memory(), 1)
  54.  
  55. def dumpcharges():
  56.     global dump_last
  57.     if print_charges:
  58.         t = time()
  59.         if not (dump_last <= t < dump_last+dump_delay):
  60.             if t <= dump_last+1.5*dump_delay:
  61.                 dump_last += dump_delay
  62.             else:
  63.                 dump_last = t
  64.             #write("%s: charges:" % who, 0)
  65.             lst = _psyco.stattop(print_charges)
  66.             if lst:
  67.                 f = t-int(t)
  68.                 lines = ["%s.%02d   ______\n" % (
  69.                     strftime("%X", localtime(int(t))),
  70.                     int(f*100.0))]
  71.                 i = 1
  72.                 for co, charge in lst:
  73.                     detail = co.co_filename
  74.                     if len(detail) > 19:
  75.                         detail = '...' + detail[-17:]
  76.                     lines.append("        #%-3d |%4.1f %%|  %-26s%20s:%d\n" %
  77.                                  (i, charge*100.0, co.co_name, detail,
  78.                                   co.co_firstlineno))
  79.                     i += 1
  80.                 current.writelines(lines)
  81.                 current.flush()
  82.  
  83. def writefinalstats():
  84.     dumpcharges()
  85.     writememory()
  86.     writedate("program exit")
  87.  
  88. def writedate(msg):
  89.     write('%s, %s' % (msg, strftime("%x")), 20)
  90.